package beans;

import java.util.ArrayList;

import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

import conversions.Conversions;
import dao.FolderDao;
import dao.ResourceDao;
import dto.FolderDTO;
import dto.ResourceDTO;

/**
 * Session Bean implementation class FolderBean
 */
@Stateless
@LocalBean
public class FolderBean implements FolderBeanRemote {

	@EJB
	FolderDao fDao;
	
	@EJB
	ResourceDao rDao;
	
	@EJB
	Conversions conv;
    /**
     * Default constructor. 
     */
    public FolderBean() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @author tokea
     * @param int repId
     * @return ArrayList<FolderDTO>
     */
	@Override
	public ArrayList<FolderDTO> getFoldersFromRepository(int repId)
	{
		ArrayList<FolderDTO> folderDTOs = null;
		folderDTOs = conv.fromFolderListToDTO(fDao.getFolderListFromRepository(repId));
		
		return folderDTOs;
	}

	/**
	 * @author tokea
	 * @param int repId
	 * @return ArrayList<ResourceDTO>
	 */
	@Override
	public ArrayList<ResourceDTO> getResourcesFromRepository(int repId)
	{
		ArrayList<ResourceDTO> resDTO = null;
		resDTO = conv.fromResourceListToDTO(rDao.getResourceListFromRepository(repId));
		return resDTO;
	}
	
	/**
	 * @author Zsombor
	 * @param FolderDTO
	 * Creates a folder
	 */
	@Override
	public FolderDTO createFolder(FolderDTO fDto){

		fDao.addFolder(fDto);
		return fDto;
	}
	
	/**
	 * @author Zsombor
	 * @param FolderDTO
	 * Deletes a folder
	 */
	@Override
	public void deleteFolder(FolderDTO fDto){

		fDao.deleteFolder(fDto.getId());
	}

	/**
	 * @author tokea
	 * @param parentId
	 * @param name
	 * @return unique
	 */
	public boolean verifyUniqueness(int parentId,String name){
		boolean unique = fDao.verifyNameUniqueInFolder(parentId, name);
		return unique;
	}
}
